package com.lijian.mapper;

import com.lijian.model.SysRole;
import com.lijian.model.SysUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoleMapper {
    @Select("select * from sys_role r")
    List<SysRole> findAllRole();

    @Select("select count(*) from sys_role r")
    Long countAllRoles();


    @Select("select * from sys_role t limit #{page}, #{limit}")
    List<SysRole> findAllRolesByPage(@Param("page")Integer offset, @Param("limit")Integer limit);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into sys_role(name, description, createTime, updateTime) values(#{name}, #{description}, #{createTime}, #{updateTime})")
    int save(SysRole role);

    @Select("select * from sys_role t where t.id = #{id}")
    SysRole findRoleById(Integer id);

    @Select("select * from sys_role t where t.name = #{roleName}")
    SysRole findRoleByRoleName(String roleName);

    int update(SysRole role);

    @Delete("delete from sys_role where id = #{id}")
    int delete(Integer id);

    @Select("select count(*) from sys_role t where t.name like '%${roleName}%'")
    Long countRoleBySearch(@Param("roleName") String roleName);

    @Select("select * from sys_role t where t.name like '%${roleName}%' limit #{page},#{limit}")
    List<SysRole> findRoleBySearch(@Param("roleName") String roleName,@Param("page")Integer offset,@Param("limit")Integer limit);
}
